// VBConversions Note: VB project level imports
using System.Diagnostics;
using System;
using System.Xml.Linq;
using System.Windows.Forms;
using System.Collections;
using System.Drawing;
using Microsoft.VisualBasic;
using System.Data;
using System.Collections.Generic;
using Microsoft.VisualBasic.Compatibility;
using System.Linq;
// End of VB project level imports

using System.IO;

namespace 喷码数据生成工具
{
	public partial class frm_TextEdit
	{
		public frm_TextEdit()
		{
			InitializeComponent();
		}
		private const long MaxSize = 10485760;
		private bool isChanged = false;
		private delegate void InvokeAppendText(string value);
		private delegate void InvokeEndRead();
		private delegate void InvokeChangeProgess(long MaxValue, long Value);
		public string FilePath;
		ArrayList TextValue = new ArrayList();
		frm_SearchWindow frmSearch;
		int CurrentSelectedIndex = 0;
		const int EM_GETLINECOUNT = 0xBA;
		frm_SearchReplaceWindow frmReplace;
		public void frm_TextEdit_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e)
		{
			e.Cancel = true;
			SaveSetting();
			if (frmReplace != null)
			{
				if (frmReplace.IsDisposed == false)
				{
					frmReplace.Close();
				}
			}
			if (frmSearch != null)
			{
				if (frmSearch.IsDisposed == false)
				{
					frmSearch.Close();
				}
			}
			if (isChanged && !(string.IsNullOrEmpty(TextBox.Text)))
			{
				if (MessageBox.Show(this, "文本内容有修改，是否先保存数据？", "询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
				{
					return ;
				}
				else
				{
					CommFunction.SaveEditeHandle.Remove(this);
					e.Cancel = false;
				}
			}
			else
			{
				CommFunction.SaveEditeHandle.Remove(this);
				e.Cancel = false;
			}
		}
		public void frm_Replace_Load(System.Object sender, System.EventArgs e)
		{
			this.Hide();
			this.MainMenu.Renderer = CommFunction.MenuSkinRender;
			this.ContextMenuObj.Renderer = CommFunction.MenuSkinRender;
			TextBox.AllowDrop = true;
			TextBox.ShowSelectionMargin = true;
			TextBox.MaxLength = 0;
			SetAppTitle("无标题");
			Tool_Time.Text = DateTime.Now.ToString();
			AutoCutLine(false);
			LoadSetting();
			CommFunction.SaveEditeHandle.Add(this);
			SetControlPosition();
			this.Show();
			
		}
		
		public void frm_Replace_Resize(object sender, System.EventArgs e)
		{
			SetControlPosition();
			if (this.WindowState == FormWindowState.Minimized)
			{
				if (frmSearch != null)
				{
					if (frmSearch.IsDisposed == false)
					{
						frmSearch.Hide();
					}
				}
				if (frmReplace != null)
				{
					if (frmReplace.IsDisposed == false)
					{
						frmReplace.Hide();
					}
				}
			}
			else if (this.WindowState == FormWindowState.Normal)
			{
				if (frmSearch != null)
				{
					if (frmSearch.IsDisposed == false)
					{
						frmSearch.Show();
					}
				}
				if (frmReplace != null)
				{
					if (frmReplace.IsDisposed == false)
					{
						frmReplace.Show();
					}
				}
			}
		}
		private void SetControlPosition()
		{
			if (this.ClientRectangle.Width <= 0 | this.ClientRectangle.Height <= 0)
			{
				return ;
			}
			TextBox.Left = 0;
			TextBox.Top = MainMenu.Height;
			TextBox.Width = this.ClientRectangle.Width;
			if (CommFunction.SaveData.EditFormData.isShowStatus)
			{
				TextBox.Height = this.ClientRectangle.Height - MainMenu.Height - StatusStrip1.Height;
			}
			else
			{
				TextBox.Height = this.ClientRectangle.Height - MainMenu.Height;
			}
			Tool_Time.Text = DateTime.Now.ToString();
			if ((double) (StatusStrip1.Width - Tool_Progress.Width) / 2 > 0)
			{
				Tool_Nothing.Width = (int) ((double) (StatusStrip1.Width - Tool_Progress.Width) / 2);
			}
			int Result = StatusStrip1.Width - Tool_Nothing.Width - Tool_Progress.Width - Tool_LineText.Width - Tool_Time.Width * 2 + 70;
			if (Result > 0)
			{
				Tool_ColText.Width = Result;
			}
		}
		public void 删除ToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
		{
			string tmp = "";
			if (!string.IsNullOrEmpty(TextBox.SelectedText))
			{
				tmp = TextBox.Text.Replace(TextBox.SelectedText, "");
				TextBox.Text = tmp;
			}
		}
		
		public void 剪切ToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
		{
			TextBox.Cut();
		}
		
		public void 时间日期ToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
		{
			TextBox.AppendText(DateTime.Now.ToString());
		}
		
		public void 全选ToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
		{
			TextBox.SelectAll();
		}
		
		public void 粘贴ToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
		{
			TextBox.Paste();
		}
		public void SetAppTitle(string value)
		{
			this.Text = value + "-文本编辑器";
		}
		
		public void 新建NToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
		{
			frm_TextEdit frm = new frm_TextEdit();
			frm.Show();
		}
		private void AutoCutLine(bool value)
		{
			if (value == true)
			{
				TextBox.WordWrap = true;
				TextBox.ScrollBars = RichTextBoxScrollBars.ForcedVertical;
			}
			else
			{
				TextBox.WordWrap = false;
				TextBox.ScrollBars = RichTextBoxScrollBars.ForcedBoth;
			}
		}
		public void 打开ToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
		{
			OpenFileDialog dialog = new OpenFileDialog();
			if (isChanged && !(string.IsNullOrEmpty(TextBox.Text)))
			{
				if (MessageBox.Show(this, "文本内容有改变，是否保存文档！", "询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
				{
					return ;
				}
				else
				{
					TextBox.Clear();
				}
			}
			dialog.Title = "打开文档";
			dialog.Filter = "文档类型(*.txt;*.dat;*.rtf;*.ini;*.html)|*.txt;*.dat;*.rtf;*.ini;*.html|所有文件(*.*)|*.*";
			dialog.FileName = "";
			dialog.CheckFileExists = true;
			
			if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
			{
				string typeStr = "." + CommFunction.getOnlyType(dialog.FileName);
				if ("*.txt;*.dat;*.ini;*.html".IndexOf(typeStr.ToLower()) > 0)
				{
					this.打开ToolStripMenuItem.Enabled = false;
					System.Threading.Thread th = default(System.Threading.Thread);
					th = new System.Threading.Thread(new System.Threading.ThreadStart(StartReadText));
					th.Start(dialog.FileName);
				}
				else if (typeStr.ToLower() == ".rtf")
				{
					TextBox.LoadFile(dialog.FileName, RichTextBoxStreamType.RichText);
				}
				FilePath = dialog.FileName;
				SetAppTitle(CommFunction.getOnlyName(dialog.FileName));
			}
		}
		private void StartReadText(string FileName)
		{
			try
			{
				if (File.Exists(FileName))
				{
					byte[] ReadByte = null;
					FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read);
					if ((double) System.Convert.ToInt32(fs.Length / 1024) / 1024 > 60)
					{
						throw (new Exception("文件大于支持的大小，最大支持60M！"));
					}
					TextValue.Clear();
					if (fs.Length > MaxSize)
					{
						long StartP = 0;
						int sCount = 0;
						string Result = "";
						int lCount = fs.Length / MaxSize;
						if (fs.Length % MaxSize != 0)
						{
							lCount++;
						}
						this.Invoke(new InvokeChangeProgess(ChanagProgress), lCount, 0);
						while (!(fs.Position >= fs.Length))
						{
							if (StartP + MaxSize < fs.Length)
							{
								//Try
								ReadByte = new byte[MaxSize - 1 + 1];
								fs.Read(ReadByte, 0, MaxSize);
								Result = TranslateByte(ReadByte);
								sCount++;
								if (sCount <= 1)
								{
									
									TextValue.Add(Result);
								}
								else
								{
									TextValue.Add(Result);
								}
							}
							else
							{
								long LeftLen = System.Convert.ToInt64(System.Convert.ToInt32(fs.Length - StartP) + 1);
								ReadByte = new byte[(int) (LeftLen - 1) + 1];
								fs.Read(ReadByte, StartP, LeftLen);
								TranslateByte(ReadByte);
								StartP = System.Convert.ToInt64(StartP + LeftLen);
								TextValue.Add(Result);
							}
							try
							{
								this.Invoke(new InvokeAppendText(AppendText), Result);
							}
							catch
							{
								MessageBox.Show(System.Convert.ToString(System.Convert.ToInt32((sCount - 1) * MaxSize) / 1024 / 1024));
							}
							this.Invoke(new InvokeChangeProgess(ChanagProgress), lCount, sCount);
						}
						
					}
					else
					{
						string Result = "";
						ReadByte = new byte[(int) (fs.Length - 1) + 1];
						fs.Read(ReadByte, 0, fs.Length);
						Result = TranslateByte(ReadByte);
						this.Invoke(new InvokeAppendText(AppendText), Result);
						TextValue.Add(Result);
					}
					fs.Close();
					this.Invoke(new InvokeEndRead(EndRead));
				}
				try
				{
					isChanged = false;
					System.Threading.Thread gth = System.Threading.Thread.CurrentThread;
					gth.Abort();
				}
				catch
				{
					try
					{
						System.Threading.Thread gth = System.Threading.Thread.CurrentThread;
						gth.Abort();
					}
					catch
					{
						
					}
				}
			}
			catch (Exception ex)
			{
				if (ex.Message != "正在中止线程。")
				{
					MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
				}
				try
				{
					System.Threading.Thread gth = System.Threading.Thread.CurrentThread;
					gth.Abort();
				}
				catch
				{
					
				}
			}
		}
		private void ChanagProgress(long MaxValue, long Value)
		{
			// If MaxValue > 1 Then Tool_Progress.Maximum = MaxValue
			// If Value >= 0 And Value <= Tool_Progress.Maximum Then Tool_Progress.Value = Value
			LB_ShowProgress.Text = Strings.Format((double) System.Convert.ToInt32(Value / MaxValue) * 100, "00") + "%";
		}
		private void EndRead()
		{
			this.打开ToolStripMenuItem.Enabled = true;
			MessageBox.Show(this, "数据读取结束！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
		}
		private string TranslateByte(byte[] Data)
		{
			string tmp = "";
			tmp = System.Text.Encoding.Default.GetString(Data);
			return tmp;
		}
		private void AppendText(string Value)
		{
			TextBox.AppendText(Value);
		}
		public void 字体ToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
		{
			FontDialog fDialog = new FontDialog();
			fDialog.AllowScriptChange = true;
			fDialog.AllowVectorFonts = true;
			fDialog.AllowVerticalFonts = true;
			fDialog.FontMustExist = true;
			fDialog.ShowApply = true;
			fDialog.ShowColor = true;
			fDialog.ShowEffects = true;
			fDialog.Color = TextBox.ForeColor;
			fDialog.Font = TextBox.Font;
			if (fDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
			{
				TextBox.SelectionColor = fDialog.Color;
				TextBox.SelectionFont = fDialog.Font;
			}
		}
		
		public void 字体颜色ToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
		{
			ColorDialog dcolor = new ColorDialog();
			dcolor.AnyColor = true;
			dcolor.SolidColorOnly = false;
			if (dcolor.ShowDialog() == System.Windows.Forms.DialogResult.OK)
			{
				TextBox.ForeColor = dcolor.Color;
			}
		}
		
		public void 自动换行ToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
		{
			自动换行ToolStripMenuItem.Checked = !自动换行ToolStripMenuItem.Checked;
			if (自动换行ToolStripMenuItem.Checked)
			{
				TextBox.ScrollBars = RichTextBoxScrollBars.ForcedVertical;
				TextBox.WordWrap = true;
			}
			else
			{
				TextBox.ScrollBars = RichTextBoxScrollBars.ForcedBoth;
				TextBox.WordWrap = false;
			}
		}
		
		public void Timer1_Tick(System.Object sender, System.EventArgs e)
		{
			Tool_Time.Text = DateTime.Now.ToString();
		}
		
		public void 状态栏ToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
		{
			状态栏ToolStripMenuItem.Checked = !状态栏ToolStripMenuItem.Checked;
			StatusStrip1.Visible = 状态栏ToolStripMenuItem.Checked;
			if (StatusStrip1.Visible == true)
			{
				TextBox.Height = this.ClientRectangle.Height - MainMenu.Height - StatusStrip1.Height;
			}
			else
			{
				TextBox.Height = this.ClientRectangle.Height - MainMenu.Height;
			}
		}
		
		public void TextBox_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
		{
			if (!string.IsNullOrEmpty(TextBox.Text) && isChanged)
			{
				if (MessageBox.Show(this, "是否保存已有内容？", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
				{
					保存SToolStripMenuItem_Click(sender, new EventArgs());
					TextBox.Text = "";
				}
				else
				{
					TextBox.Text = "";
				}
			}
			else
			{
				TextBox.Text = "";
			}
			if (e.Data.GetDataPresent(DataFormats.FileDrop))
			{
				string[] FileName = e.Data.GetData(DataFormats.FileDrop, false);
				if (FileName.Length > 2)
				{
					MessageBox.Show(this, "一次只能拖动一个文件！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
				}
				return ;
				//For i = 0 To FileName.Length - 1
				//    TextBox.AppendText(vbCrLf & FileName(i))
				//Next
//				string sFileName = FileName[0];
//				string typeStr = "." + CommFunction.getOnlyType(sFileName);
//				if ("*.txt;*.dat;*.ini;*.html".IndexOf(typeStr.ToLower()) > 0)
//				{
//					this.打开ToolStripMenuItem.Enabled = false;
//					System.Threading.Thread th = default(System.Threading.Thread);
//					th = new System.Threading.Thread(new System.Threading.ThreadStart(StartReadText));
//					th.Start(sFileName);
//					}
//					else if (typeStr.ToLower() == ".rtf")
//					{
//						TextBox.LoadFile(sFileName, RichTextBoxStreamType.RichText);
//						}
//						else
//						{
//							MessageBox.Show(this, "不支持该文件格式！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
//							return ;
//							}
//							FilePath = sFileName;
//							SetAppTitle(CommFunction.getOnlyName(sFileName));
						}
						else if (e.Data.GetDataPresent(DataFormats.Html))
						{
							TextBox.AppendText(System.Convert.ToString(e.Data.GetData(DataFormats.UnicodeText)));
						}
					}
					
					public void TextBox_LinkClicked(object sender, System.Windows.Forms.LinkClickedEventArgs e)
					{
						if (MessageBox.Show(this, "是否打开点击网页？", "询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
						{
							Process.Start(e.LinkText);
						}
					}
					
					public void TextBox_LostFocus(object sender, System.EventArgs e)
					{
						
					}
					
					public void TextBox_MouseDown(System.Object sender, System.Windows.Forms.MouseEventArgs e)
					{
						
					}
					public void LoadSetting()
					{
						//==================load from local data
						this.状态栏ToolStripMenuItem.Checked = CommFunction.SaveData.EditFormData.isShowStatus;
						this.自动换行ToolStripMenuItem.Checked = CommFunction.SaveData.EditFormData.isWordWrap;
						if (CommFunction.SaveData.EditFormData.formWindowState == FormWindowState.Maximized)
						{
							this.WindowState = FormWindowState.Maximized;
						}
						else if (CommFunction.SaveData.EditFormData.formWindowState == FormWindowState.Minimized)
						{
							this.WindowState = FormWindowState.Minimized;
						}
						else
						{
							this.WindowState = FormWindowState.Normal;
							if (CommFunction.SaveData.EditFormData.frmX > 0)
							{
								this.Left = CommFunction.SaveData.EditFormData.frmX;
							}
							if (CommFunction.SaveData.EditFormData.frmY > 0)
							{
								this.Top = CommFunction.SaveData.EditFormData.frmY;
							}
							if (CommFunction.SaveData.EditFormData.frmHeight > 0)
							{
								this.Height = CommFunction.SaveData.EditFormData.frmHeight;
							}
							if (CommFunction.SaveData.EditFormData.frmWidth > 0)
							{
								this.Width = CommFunction.SaveData.EditFormData.frmWidth;
							}
						}
						if (CommFunction.SaveData.EditFormData.TextFont != null)
						{
							TextBox.Font = CommFunction.SaveData.EditFormData.TextFont;
						}
						TextBox.ForeColor = CommFunction.SaveData.EditFormData.TextColor;
						//=========================================
						StatusStrip1.Visible = CommFunction.SaveData.EditFormData.isShowStatus;
						if (CommFunction.SaveData.EditFormData.isShowStatus)
						{
							TextBox.Height = this.ClientRectangle.Height - MainMenu.Height - StatusStrip1.Height;
						}
						else
						{
							TextBox.Height = this.ClientRectangle.Height - MainMenu.Height;
						}
						if (自动换行ToolStripMenuItem.Checked)
						{
							TextBox.ScrollBars = RichTextBoxScrollBars.ForcedVertical;
							TextBox.WordWrap = true;
						}
						else
						{
							TextBox.ScrollBars = RichTextBoxScrollBars.ForcedBoth;
							TextBox.WordWrap = false;
						}
					}
					private void SaveSetting()
					{
						CommFunction.SaveData.EditFormData.formWindowState = this.WindowState;
						CommFunction.SaveData.EditFormData.frmHeight = this.Height;
						CommFunction.SaveData.EditFormData.frmWidth = this.Width;
						CommFunction.SaveData.EditFormData.frmX = this.Left;
						CommFunction.SaveData.EditFormData.frmY = this.Top;
						CommFunction.SaveData.EditFormData.isWordWrap = this.自动换行ToolStripMenuItem.Checked;
						CommFunction.SaveData.EditFormData.isShowStatus = this.状态栏ToolStripMenuItem.Checked;
						CommFunction.SaveData.EditFormData.TextFont = TextBox.Font;
						CommFunction.SaveData.EditFormData.TextColor = TextBox.ForeColor;
					}
					
					public void TextBox_SelectionChanged(object sender, System.EventArgs e)
					{
						var pos = TextBox.GetPositionFromCharIndex(TextBox.SelectionStart);
						var x = TextBox.GetCharIndexFromPosition(pos);
						var y = TextBox.GetLineFromCharIndex(TextBox.SelectionStart);
						var a = TextBox.GetFirstCharIndexOfCurrentLine();
						Tool_LineText.Text = "行：" + System.Convert.ToString(y + 1);
						Tool_ColText.Text = "列：" + System.Convert.ToString(x - a + 1);
					}
					public void TextBox_TextChanged(object sender, System.EventArgs e)
					{
						isChanged = true;
						Tool_Progress.Text = "总行数:" + System.Convert.ToString(getLineCount());
					}
					
					public void 复制ToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
					{
						Clipboard.SetText(TextBox.SelectedText);
					}
					
					public void 撤销ToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
					{
						TextBox.Undo();
					}
					
					public void 重复RToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
					{
						TextBox.Redo();
					}
					
					public void 保存SToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
					{
						if (File.Exists(FilePath) == false)
						{
							SaveFileDialog Dialog = new SaveFileDialog();
							Dialog.Title = "保存";
							Dialog.Filter = "文本文档(*.txt)|*.txt|富文本(*.rtf)|*.rtf|配置文件(*.ini)|*.ini|网页文件(*.html)|*.html|*.dat(*.dat)|*.dat";
							Dialog.CheckPathExists = true;
							Dialog.DefaultExt = "*.txt";
							if (Dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
							{
								FilePath = Dialog.FileName;
							}
							else
							{
								FilePath = "";
								return ;
							}
						}
						SaveFile();
					}
					private void SaveFile()
					{
						isChanged = false;
						string typeStr = CommFunction.getOnlyType(FilePath);
						if (string.IsNullOrEmpty(typeStr))
						{
							TextBox.SaveFile(FilePath, RichTextBoxStreamType.TextTextOleObjs);
						}
						else
						{
							switch (typeStr.ToLower())
							{
								case "txt":
									TextBox.SaveFile(FilePath, RichTextBoxStreamType.TextTextOleObjs);
									break;
								case "rtf":
									TextBox.SaveFile(FilePath, RichTextBoxStreamType.RichText);
									break;
								case "ini":
									TextBox.SaveFile(FilePath, RichTextBoxStreamType.TextTextOleObjs);
									break;
								case "dat":
									TextBox.SaveFile(FilePath, RichTextBoxStreamType.TextTextOleObjs);
									break;
								case "html":
									TextBox.SaveFile(FilePath, RichTextBoxStreamType.TextTextOleObjs);
									break;
							}
						}
						SetAppTitle(CommFunction.getOnlyName(FilePath));
					}
					
					public void 另存为AToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
					{
						SaveFileDialog Dialog = new SaveFileDialog();
						Dialog.Title = "保存";
						Dialog.Filter = "文本文档(*.txt)|*.txt|富文本(*.rtf)|*.rtf|配置文件(*.ini)|*.ini|网页文件(*.html)|*.html|*.dat(*.dat)|*.dat";
						Dialog.CheckPathExists = true;
						Dialog.DefaultExt = "*.txt";
						if (Dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
						{
							FilePath = Dialog.FileName;
							SaveFile();
						}
						else
						{
							//  FilePath = ""
							return ;
						}
					}
					
					public void 退出EscToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
					{
						this.Close();
					}
					
					public void 关于ToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
					{
						MessageBox.Show(this, "名  称：文本编辑器" + "\r\n" + "版  本：v1.0.0.0" + "\r\n" + "作  者：莫书江(e_mail:250933400@qq.com)", "关于", MessageBoxButtons.OK, MessageBoxIcon.Information);
					}
					
					public void 撤销ToolStripMenuItem1_Click(System.Object sender, System.EventArgs e)
					{
						this.撤销ToolStripMenuItem_Click(sender, e);
					}
					
					public void 复制ToolStripMenuItem1_Click(object sender, System.EventArgs e)
					{
						复制ToolStripMenuItem_Click(sender, e);
					}
					
					public void 重复RToolStripMenuItem1_Click(System.Object sender, System.EventArgs e)
					{
						this.重复RToolStripMenuItem_Click(sender, e);
					}
					
					public void 剪切CToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
					{
						this.剪切ToolStripMenuItem_Click(sender, e);
					}
					
					public void 粘贴PToolStripMenuItem_Click(object sender, System.EventArgs e)
					{
						粘贴ToolStripMenuItem_Click(sender, e);
					}
					
					public void 删除DToolStripMenuItem_Click(object sender, System.EventArgs e)
					{
						删除ToolStripMenuItem_Click(sender, e);
					}
					
					public void 全选AToolStripMenuItem_Click(object sender, System.EventArgs e)
					{
						全选ToolStripMenuItem_Click(sender, e);
					}
					
					public void 日期ToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
					{
						时间日期ToolStripMenuItem_Click(sender, e);
						
					}
					
					public void TextBox_VScroll(object sender, System.EventArgs e)
					{
						Point sPt = new Point(0, 0);
						long a;
						a = TextBox.GetCharIndexFromPosition(sPt);
					}
					
					public void 查找ToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
					{
						if (frmSearch == null)
						{
							frmSearch = new frm_SearchWindow(this, TextBox.SelectedText);
						}
						if (frmSearch.IsDisposed)
						{
							frmSearch = new frm_SearchWindow(this, TextBox.SelectedText);
						}
						//  SetParent(frmSearch.Handle.ToInt32, Me.Handle.ToInt32)
						frmSearch.Left = (int) (this.Left + (double) (this.Width - frmSearch.Width) / 2);
						frmSearch.Top = (int) (this.Top + (double) (this.Height - frmSearch.Height) / 2);
						frmSearch.TopMost = true;
						frmSearch.FatherForm = this;
						frmSearch.Show();
						if (frmReplace != null)
						{
							if (frmReplace.IsHandleCreated)
							{
								frmReplace.Close();
							}
						}
					}
					public long getLineCount()
					{
						return sAPI.SendMessage(TextBox.Handle.ToInt32(), EM_GETLINECOUNT, 0, 0);
					}
					
					public void 替换RToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
					{
						if (frmReplace == null)
						{
							frmReplace = new frm_SearchReplaceWindow(TextBox.SelectedText);
						}
						if (frmReplace.IsDisposed)
						{
							frmReplace = new frm_SearchReplaceWindow(TextBox.SelectedText);
						}
						frmReplace.FatherForm = this;
						frmReplace.Left = (int) (this.Left + (double) (this.Width - frmReplace.Width) / 2);
						frmReplace.Top = (int) (this.Top + (double) (this.Height - frmReplace.Height) / 2);
						frmReplace.TopMost = true;
						frmReplace.Show();
						if (frmSearch != null)
						{
							if (frmSearch.IsHandleCreated)
							{
								frmSearch.Close();
							}
						}
					}
				}
			}
